package cn.stylefeng.guns.config.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @Author: 宋旭
 * @Date: Created in 16:03 2017/7/12/012
 */
@Component
public class RedisHandler {

    @Autowired
    private GlobalRedisTemplate globalRedisTemplate;

    @Autowired
    StringRedisTemplate redisTemplate;

    /**
     * 服务自身redis工具类
     */
    private RedisTemplateUtil selfRedisTemplateUtil;


    /**
     * 全局redis工具类
     */

    private RedisTemplateUtil globalRedisTemplateUtil;

    /**
     * 获取全局redis操作类
     *
     * @return
     */

    public RedisTemplateUtil getGlobalRedisTemplate() {
        if (globalRedisTemplateUtil == null) {
            globalRedisTemplateUtil = new RedisTemplateUtil(globalRedisTemplate);
        }
        return globalRedisTemplateUtil;
    }

    /**
     * 获取服务自身redis操作类
     */
    public RedisTemplateUtil getLocalRedisTemplate() {
        if (selfRedisTemplateUtil == null) {
            selfRedisTemplateUtil = new RedisTemplateUtil(redisTemplate);
        }
        return selfRedisTemplateUtil;
    }
}
